package sunwin.yoms.service.security;

import jodd.util.BCrypt;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * Created by 田西泽 on 2015-8-13.
 */
@SuppressWarnings("unchecked")
public class YomsPasswordEncoder implements PasswordEncoder {
    @Override
    public String encode(CharSequence rawPassword) {
        return rawPassword.toString();
    }

    @Override
    public boolean matches(CharSequence rawPassword, String encodedPassword) {
        try {
            return BCrypt.checkpw(rawPassword.toString(), encodedPassword);
        } catch (IllegalArgumentException e) {
            return false;
        }
    }
}